#!usr/bin/env python  
# -*- coding:utf-8 -*-
""" 
@author:robot
@file: level_traversal.py 
@version:
@time: 2024/01/27 
"""
from collections import deque


def visit_tree(root):
    if not root:
        return

    queue = deque([root])
    while queue:
        node = queue.popleft()
        print(node.val)
        if node.left:
            queue.append(node.left)
        if node.right:
            queue.append(node.right)


class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None


node1 = TreeNode(1)
node2 = TreeNode(2)
node3 = TreeNode(3)
node4 = TreeNode(4)
node5 = TreeNode(5)
node6 = TreeNode(6)
node1.left = node2
node1.right = node3
node2.left = node4
node3.left = node5
node3.right = node6

visit_tree(node1)
